import { create } from 'zustand';
import { persist } from 'zustand/middleware';

interface Settings {
  systemName: string;
  systemLogo: string;
  itemsPerPage: number;
  dateFormat: string;
  language: string;
  enableDarkMode: boolean;
  enableNotifications: boolean;
  storageType: 'local' | 's3' | 'oss';
  storagePath: string;
  embeddingModel: string;
  vectorDbType: string;
  chunkSize: number;
  enableMFA: boolean;
  sessionTimeout: number;
  passwordPolicy: 'simple' | 'medium' | 'strong';
  apiEndpoint: string;
  logLevel: 'debug' | 'info' | 'warn' | 'error';
}

interface SettingsState extends Settings {
  saveSettings: (settings: Partial<Settings>) => void;
  resetSettings: () => void;
}

const defaultSettings: Settings = {
  systemName: '企业知识库管理平台',
  systemLogo: '/logo.png',
  itemsPerPage: 10,
  dateFormat: 'YYYY-MM-DD',
  language: 'zh-CN',
  enableDarkMode: false,
  enableNotifications: true,
  storageType: 'local',
  storagePath: '/data/storage',
  embeddingModel: 'openai',
  vectorDbType: 'pinecone',
  chunkSize: 500,
  enableMFA: false,
  sessionTimeout: 30,
  passwordPolicy: 'medium',
  apiEndpoint: 'https://api.example.com',
  logLevel: 'info',
};

export const useSettingsStore = create<SettingsState>()(
  persist(
    (set) => ({
      ...defaultSettings,
      
      saveSettings: (settings) => {
        set((state) => ({ ...state, ...settings }));
      },
      
      resetSettings: () => {
        set(defaultSettings);
      },
    }),
    {
      name: 'knowledge-platform-settings',
    }
  )
); 